package comnet.ftpclient;

import java.io.IOException;
import java.net.ConnectException;
import java.net.Socket;

/**
 * @author Mikko Puustinen (mikko.puustinen@gmail.com)
 * @version 0.1, 2008-jan-11
 */
public class SftpConnection {
    private String host;
    private int port;
    private Socket commandSocket;

    /**
     * @param host
     * @param port
     */
    public SftpConnection(String host, int port) {
        this.host = host;
        this.port = port;
    }

    /**
     * Opens the connection to the host.
     *
     * @throws java.io.IOException
     */
    public void openConnection() throws IOException {
        try {
            commandSocket = new Socket(host, port);
        } catch (ConnectException e) {
            throw new ConnectException("Host unreachable");
        }
    }

    /**
     * Returns the socket the command connection is using.
     *
     * @return
     */
    public Socket getCommandSocket() {
        return commandSocket;
    }

    /**
     *
     */
    public void requestDataConnection() {
        //FIXME: Not implemented yet
    }

    /**
     * Opens a data connection to the specified host.
     *
     * @param dataHost
     * @param dataPort
     *
     * @return
     *
     * @throws java.io.IOException
     */
    public Socket openDataConnection(String dataHost, int dataPort) throws IOException {
        return new Socket(dataHost, dataPort);
    }

    /**
     * Opens a data connection to the host specified when this object was
     * created.
     *
     * @param dataPort
     *
     * @return
     *
     * @throws java.io.IOException
     */
    public Socket openDataConnection(int dataPort) throws IOException {
        return openDataConnection(host, dataPort);
    }

    /**
     * @param port
     */
    public void connect(int port) {

    }

    /**
     * @param host
     * @param port
     */
    public void connect(String host, int port) {

    }
}
